package main

import (
	"context"
	"fmt"
	"log"
	"net"

	"gitee.com/kratos-learning/service-register-discovery/grpc/pb"
	"google.golang.org/grpc"
)

/*
1、gRPC是绑定到一个端口上，标准库是绑定在多个上
2、函数必须监听之前注册

*/

type HelloServiceImpl struct{}

func (p *HelloServiceImpl) Hello(ctx context.Context, args *pb.String) (*pb.String, error) {
	reply := &pb.String{Value: "hello:" + args.GetValue()}
	fmt.Println(args.Value)
	return reply, nil
}
func main() {
	grpcServer := grpc.NewServer()
	pb.RegisterHelloServiceServer(grpcServer, new(HelloServiceImpl)) //函数必须监听之前注册

	lis, err := net.Listen("tcp", ":1234")
	if err != nil {
		log.Fatal(err)
	}
	grpcServer.Serve(lis) //gRPC是绑定到某个端口上，标准库是绑定在多个上
	// pb.RegisterHelloServiceServer(grpcServer, new(HelloServiceImpl)) //监听之后才注册会不成功
}
